﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQuery;
using mshtml;

namespace Ikariam.MQuery
{
    /// <summary>
    /// Summary description for ExtensionsTest
    /// </summary>
    [TestClass]
    public class MQueryExtensionsTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        HTMLDocumentClass document;

        [TestInitialize]
        public void TestInitialize()
        {
            document = MQueryUnitTest.Load("http://localhost/JQueryTest1.htm");
        }
        [TestCleanup]
        public void TestCleanup()
        {
            MQueryUnitTest.Quit();
        }

        [Owner("Yehuda Adar")]
        [TestMethod]
        public void Text()
        {
            string id = "DivID1";
            Query query = new Query("#" + id, document);
            Assert.AreEqual(query[0].Text(), query[0].innerText);
            return;
        }

        [Owner("Yehuda Adar")]
        [TestMethod]
        public void HasClass()
        {
            string selector = "Div H1";
            Query query = new Query(selector, document);
            Assert.IsTrue(query[0].HasClass("Class2"));
        }

        [Owner("Yehuda Adar")]
        [TestMethod]
        public void Traverse()
        {
            string selector = "#DivID3 B";
            Query query = new Query(selector, document);

            string selector2 = "#DivID3";
            Query query2 = new Query(selector2, document);

            int index = 0;

            query2[0].Traverse(x => ++index);

            Assert.AreEqual(query.Length, index - 1);
        }
    }
}
